package com.yidu.controller;

import com.yidu.entity.AmUser;
import com.yidu.service.AmUserRoleService;
import com.yidu.service.AmUserService;
import com.yidu.utils.BaseMessage;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

/**
 * 用户表(AmUser)表控制层
 *
 * @author wanghong
 * @since 2021-08-02 11:48:28
 */
@RestController
@RequestMapping("amUser")
public class AmUserController {
    /**
     * 服务对象
     */
    @Autowired
    private AmUserService amUserService;

    @Autowired
    private AmUserRoleService amUserRoleService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public AmUser selectOne(Integer id) {
        return this.amUserService.queryById(id);
    }

    /**
     * 登录
     *
     * @param user
     * @return
     */
    @RequestMapping("login")
    @ResponseBody
    public Map<String,Object> login(AmUser user){
        AmUser amUser = amUserService.findNameAndPwd(user);
        if (amUser!=null){
            return BaseMessage.judge("1",amUser.getRealName()+"欢迎回来",amUser);

        }else {
            return BaseMessage.judge("0","登录失败，请检查账号和密码是否正确");
        }
    }



}
